﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq.Expressions;

namespace Lucene.Linq.Expressions
{
    internal class SelectExpression : Expression
    {
        private readonly string _alias;
        private readonly string[] _defaultFieldNames;
        private readonly ReadOnlyCollection<FieldDeclaration> _fields;
        private readonly Expression _from;
        private readonly Expression _where;

        internal SelectExpression(Type type, string alias, IEnumerable<FieldDeclaration> fields,
                                  string[] defaultFieldNames, Expression from, Expression where)
            : base((ExpressionType) LuceneExpressionType.Select, type)
        {
            _alias = alias;
            _fields = fields as ReadOnlyCollection<FieldDeclaration>
                      ?? new List<FieldDeclaration>(fields).AsReadOnly();

            _defaultFieldNames = defaultFieldNames;

            _from = from;
            _where = where;
        }

        internal string Alias
        {
            get { return _alias; }
        }

        internal ReadOnlyCollection<FieldDeclaration> Fields
        {
            get { return _fields; }
        }

        internal string[] DefaultFieldNames
        {
            get { return _defaultFieldNames; }
        }

        internal Expression From
        {
            get { return _from; }
        }

        internal Expression Where
        {
            get { return _where; }
        }
    }
}